//
//  URL+Extension.swift
//  LiveTrivia
//
//  Created by iOS on 2018/8/7.
//  Copyright © 2018年 LiveTrivia. All rights reserved.
//

import UIKit
import Foundation

extension URL {
    
    var domain: String? {
        guard let host = host else {
            return nil
        }
        guard !host.isValidIP() else {
            return host
        }
        let array = host.components(separatedBy: ".")
        guard array.count > 2 else {
            return host
        }
        
        return array[array.count - 2] + "." + array[array.count - 1]
    }
}
